package com.itheima.health.h5.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.dto.RoleDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.*;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.RoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "角色模块管理")
public class RoleController {
    @Reference
    private RoleService roleService;
    @Reference
    private PermissionService permissionService;
    @Reference
    private MenuService menuService;
    //   开发 检查项模块   crud


    @GetMapping("role/findAll")
    public Result findAll() {
        List<Permission> list = permissionService.list();
        return new Result(list);
    }

    @GetMapping("role/findAllMenu")
    public Result findAllMenu() {
        List<Menu> list = menuService.findAllMenu();
        return new Result(list);
    }

    @PostMapping("role/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        Result page = roleService.findPage(queryPageBean);
        return page;
    }

    @PostMapping("role/add")
    public Result add(@RequestBody RoleDTO roleDTO) {
        Boolean flag = roleService.add(roleDTO);

        return new Result(flag);
    }

    @GetMapping("role/permissionIdsByRoleId/{id}")
    public Result deleteCheckItemById(@PathVariable("id") int id){
        RoleVO roleVO = roleService.findPermissionIdsbyRoleId(id);

        return new Result(roleVO);
    }

//    @GetMapping("role/menuIdsByRoleId/{id}")
//    public Result menuIdsbyGRoleId(@PathVariable("id") int id){
//        RoleVO roleVO = roleService.findMenuIdsbyGRoleId(id);
//
//        return new Result(roleVO);
//    }

    @DeleteMapping("role/deleteById/{id}")
    public Result deleteById(@PathVariable("id") int id){
        Boolean flag = roleService.deleteById(id);

        return new Result(flag);
    }

}

